package com.zc.webnews.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zc.webnews.R;
import com.zc.webnews.bean.NewsDetailsBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chuan on 2016/12/6.
 */

public class CollectionAdapter extends BaseAdapter {
    private List<NewsDetailsBean> list = new ArrayList<>();
    private Context context;
    public CollectionAdapter(Context context, List<NewsDetailsBean> list){
        this.context = context;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolders holders;
        if (convertView == null){
            holders = new ViewHolders();
            convertView = LayoutInflater.from(context).inflate(R.layout.news_items,null);
            holders.title = (TextView) convertView.findViewById(R.id.news_item_title);
            holders.content = (TextView) convertView.findViewById(R.id.news_item_text);
            holders.date = (TextView) convertView.findViewById(R.id.news_item_time);
            holders.iv_collect = (ImageView) convertView.findViewById(R.id.news_item_collected);
            holders.tv_collect = (TextView) convertView.findViewById(R.id.news_tv_item_collected);
            convertView.setTag(holders);
        }else {
            holders = (ViewHolders) convertView.getTag();
        }
        holders.title.setText(list.get(position).getTitle());
        holders.content.setText(list.get(position).getDescription());
        holders.date.setText(list.get(position).getPubDate());
        return convertView;
    }

    class ViewHolders{
        TextView title;
        TextView content;
        TextView date;
        TextView tv_collect;
        ImageView iv_collect;
    }
}
